🚀 Le Scénario

Supply Chain Chaos 📉

Ships are arriving in a scrambled order. We need to calculate the Indice de Chaos (number of inversions) to optimize the AI traffic controller.

Qu'est-ce qu'une inversion ?

A pair of indices $(i, j)$ is an inversion if:

  • $i < j$ (le bateau $i$ arrive avant $j$)
  • $A[i] > A[j]$ (le bateau $i$ a un identifiant de priorité plus élevé)

Analysis 🔍

Séquence d'exemple : [2, 4, 1, 3, 5]

  • (2, 1): 2 arrive avant 1, mais 2 > 1
  • (4, 1): 4 arrive avant 1, mais 4 > 1
  • (4, 3): 4 arrive avant 3, mais 4 > 3
  • Chaos total : 3 inversions

Le Défi

A brute force nested loop is $O(N^2)$.

for i in range(n):
  for j in range(i+1, n): ...

For $N=100,000$, this takes ~10 billion ops. Résultat : dépassement du délai imparti.